#include "systemfailurecontrolleer.h"

SystemFailureController::SystemFailureController(QObject *parent)
    : QObject{parent}
{
    systemFailureView = new SystemFailureView();
    setNextStationName("上海站");
    setDestinationStationName("北京站");
    setTerminusPlatformNumber("2022");
    setServiceNumber("2021");
    setSelfTestingFailure(true);
    setCbtcRadioFailure(true);
    setOverSpeedFailure(true);
    setTheATOStartButton(true);
    setTrainHasNotLocalized(true);
    setTrainHasNotInitialized(true);
}

SystemFailureController::~SystemFailureController()
{

}

void SystemFailureController::show(QVBoxLayout *vLayout, int stretch)
{
    vLayout->addWidget(systemFailureView,stretch);
}
//设置下一站名字
void SystemFailureController::setNextStationName(QString name)
{
    systemFailureView->pushButton[0]->setText("下一站:\n" + name);
}
//设置终点站名字
void SystemFailureController::setDestinationStationName(QString name)
{
  systemFailureView->pushButton[1]->setText("终点站:\n" + name);
}
//列车总站月台号码(4位数字)
void SystemFailureController::setTerminusPlatformNumber(QString num)
{
  systemFailureView->pushButton[2]->setText(num);
}
//服务号码(3位)和行程号码(2位)
void SystemFailureController::setServiceNumber(QString num)
{
    systemFailureView->pushButton[3]->setText(num);
}

//是否显示自检失败告警
void SystemFailureController::setSelfTestingFailure(bool state)
{
    systemFailureView->pushButton[4]->setText(state ?"自检失败":"");
    if(state){
        systemFailureView->pushButton[4]->setStyleSheet("QPushButton{ background-color:red;}");
    }else{
        systemFailureView->pushButton[4]->setStyleSheet("QPushButton{ background-color:transparent;}");
    }

}

//是否显示CBTC无线电故障告警
void SystemFailureController::setCbtcRadioFailure(bool state)
{
    systemFailureView->pushButton[5]->setText(state ?"通信故障":"");
    if(state){
        systemFailureView->pushButton[5]->setStyleSheet("QPushButton{ background-color:red;}");
    }else{
        systemFailureView->pushButton[5]->setStyleSheet("QPushButton{ background-color:transparent;}");
    }
}
//是否显示超速故障告警
void SystemFailureController::setOverSpeedFailure(bool state)
{
    systemFailureView->pushButton[6]->setText(state ?"超速":"");
    if(state){
        systemFailureView->pushButton[6]->setStyleSheet("QPushButton{ background-color:red;}");
    }else{
        systemFailureView->pushButton[6]->setStyleSheet("QPushButton{ background-color:transparent;}");
    }
}
//是否显示ATO启动按钮(ATO)表示ATO启动按钮失效告警
void SystemFailureController::setTheATOStartButton(bool state)
{
    systemFailureView->pushButton[7]->setText(state ?"ATO发车按钮\n故障":"");
    if(state){
        systemFailureView->pushButton[7]->setStyleSheet("QPushButton{ background-color:red;}");
    }else{
        systemFailureView->pushButton[7]->setStyleSheet("QPushButton{ background-color:transparent;}");
    }
}
//是否显示表示列车没有本地化报警
void SystemFailureController::setTrainHasNotLocalized(bool state)
{
    systemFailureView->pushButton[8]->setText(state ?"无定位":"");
    if(state){
        systemFailureView->pushButton[8]->setStyleSheet("QPushButton{ background-color:red;}");
    }else{
        systemFailureView->pushButton[8]->setStyleSheet("QPushButton{ background-color:transparent;}");
    }
}


//是否显示NOT REGISTER(恐吓信)表示列车没有初始化报警
void SystemFailureController::setTrainHasNotInitialized(bool state)
{
    systemFailureView->pushButton[9]->setText(state ?"未注册":"");
    if(state){
        systemFailureView->pushButton[9]->setStyleSheet("QPushButton{ background-color:red;}");
    }else{
        systemFailureView->pushButton[9]->setStyleSheet("QPushButton{ background-color:transparent;}");
    }
}



